<?php defined('_JEXEC') or die('Restricted access'); ?>
<?php
  $params = &JComponentHelper::getParams( 'com_odudeprofile' );
    $component = JComponentHelper::getComponent( 'com_odudeprofile' );
  $params = new JParameter( $component->params );

?>
<style>
table.fancy {
  margin: 1em 1em 1em 0;
  background: <?php echo $params->get( 'a1' ) ?>;
  border-collapse: collapse;
}
table.fancy tr:hover {
   background: <?php echo $params->get( 'a2' ) ?> !important;
}
table.fancy th, table.fancy td {
  border: 1px silver solid;
  padding: 0.2em;
}
table.fancy th {
  background: gainsboro;
  text-align: left;
}
table.fancy caption {
  margin-left: inherit;
  margin-right: inherit;
}

</style>
<?php
                           function cleanuserinput($dirty)
                             {

                             if (get_magic_quotes_gpc())
                             {
                             $clean = mysql_real_escape_string(stripslashes($dirty));
                             }
                             else
                             {
                             $clean = mysql_real_escape_string($dirty);
                             }

                              return $clean;

                              }


  		$id = JRequest::getVar('id', 0, 'request', 'int');
		$SN=JRequest::getVar('SN', 0, 'request');
		$SE=JRequest::getVar('SE', 0, 'request');
		$body=JRequest::getVar('body', 0, 'request');
		$sub=JRequest::getVar('title', 0, 'request');
		$name = JRequest::getVar('name', 0, 'request');
		
		$email = JRequest::getVar('email', 0, 'request');
		$cate=JRequest::getVar('cate', 0, 'request');

		$send = JRequest::getVar('send', 0, 'request');
		$notify = JRequest::getVar('notify', 0, 'request');

		$recipients= JRequest::getVar('recipients', '', 'post', 'string', JREQUEST_ALLOWRAW);
		if($notify!='Y')
		$notify='N';


		$tab="";

				$model =& $this->getModel();
     	         $ecardS = $model->getSetting();


			$x=0;
			if(!preg_match('/([a-zA-z0-9\.\-]+)@([a-zA-Z0-9\.\-]+)\.([a-zA-Z]{2,3})/',$SE))
			{
				echo JText::_('ECARD_SENDER_EMAIL_ERROR').": $SE<br>";
				$x++;
			}
			if($SN==null || $SN=="")
			{
				echo JText::_('ECARD_SENDER_BLANK')."<br>";
				$x++;
			}
			if($x==0)
			{

                    echo "<center><h1>".JText::_('ECARD_SENT')."</h1><table border=0 width=99% class=fancy>";
					echo "<tr align=left><th>".JText::_('ECARD_REC')."</th><th>".JText::_('ECARD_REC_EMAIL')."</th><th>".JText::_('ECARD_STATUS')."</thd></tr>";

                    for ($i=0; $i<count($name); $i++)
					{

                  //  echo "<h1>".$clock."</h1>";

                    	$status="";

						if(!preg_match('/([a-zA-z0-9\.\-]+)@([a-zA-Z0-9\.\-]+)\.([a-zA-Z]{2,3})/',$email[$i]))
						$status="X";
						else
						$status="O";


						$a=$i+1;

						if($email==null || $status=="X")
						{
						echo "<tr><td align=left>".$name[$i]."&nbsp;</td><td align=left>".$email[$i]."&nbsp;</td><td><b>".JText::_('ECARD_X')."</b></td></tr>";
						}
						else
						{


						echo "<tr><td align=left>".$name[$i]."&nbsp;</td><td align=left>".$email[$i]."&nbsp;</td><td align=center><br>".JText::_('ECARD_O')."<br> &nbsp;";
                        $dispatcher =& JDispatcher::getInstance();
                        $dispatcher->trigger('getProfilePic', array('email',$email[$i],'icon' ));

                        echo "</td></tr>";

                        	if($status=="O")
							{


                            try
                            {
                            	$clock1=JFactory::getDate()->toFormat('%Y-%m-%d');
								$xid=time()+$a;
								$db =& JFactory::getDBO();
								$query =  "insert into #__ecard_view values('$xid',".$db->quote($SN).",'$SE',".$db->quote($name[$i]).",'$email[$i]','$clock1','".cleanuserinput($sub)."','".cleanuserinput($body)."','$notify','Y','$id')";
								$db->setQuery($query);
								$result = $db->query();

								$from = $ecardS['from_email'];
								$fromname = $SN;
								$recipient = $email[$i];
								$subject = $ecardS['subject_suffix'];
								$replyto = $SE;
								$replytoname = $SN;


								$u =& JURI::getInstance();
								$linc=$u->getScheme()."://".$u->getHost().JRoute::_("index.php?option=com_odudecard&amp;xid=$xid&amp;controller=odudecardpick&amp;notify=$notify&amp;cate=$cate");
								$body1 = JText::_('ECARD_HELLO')." $name[$i],<br><br>".JText::_('ECARD_I_HAVE')."<br>".JText::_('ECARD_PICK')."<br><br><a href=".$linc.">".$linc."</a><br><br>".JText::_('ECARD_THANK')."<br>$SN";

                                $mode = 1;
							//	echo "<b>$query </b>";
								//echo $linc."<hr>";

							//	JUtility::sendMail($from, $fromname, $recipient, $subject, $body1, $mode,'','','',$replyto, $replytoname);
          $mailer =& JFactory::getMailer();
           $config =& JFactory::getConfig();
           $sender = array(   $from, $fromname );

           $mailer->setSender($sender);
            $mailer->addReplyTo(array($replyto, $replytoname));
           //$user =& JFactory::getUser();
           //$recipient = $user->email;
           //$recipient = array( 'person1@domain.com', 'person2@domain.com', 'person3@domain.com' );
           $mailer->addRecipient($recipient);
           $mailer->setSubject($subject);
           $mailer->setBody($body1);
           $mailer->isHTML(true);
		$send =& $mailer->Send();
                            }
                            catch (Exception $e)
                             {
                            echo 'Caught exception: ',  $e->getMessage(), "\n";

                             }


							}

						}
					}



					echo "</table></center><br><a href=".JRoute::_("index.php?option=com_odudecard")."><strong>".JText::_('ECARD_NEW')."</strong></a>";


			}
			else
			{
				echo "<br>".JText::_('ECARD_CANNOT')." <a href=javascript:history.back()>".JText::_('ECARD_BACK')."</a>";


			}

echo $tab;
?>

<BR><a href=http://www.odude.com target=_blank ><img src="components/com_odudecard/images/dot.gif" border=0 align=right></a>
